<?php

declare(strict_types=1);

namespace App\Models;

use App\Common\Traits\HasAttachments;
use Hyperf\Database\Model\Builder;

class CommodityActivityPushMaterial extends Base
{
    use HasAttachments;

    /**
     * 素材类型: 文字
     */
    const TYPE_TEXT = 1;

    /**
     * 素材类型: 图片
     */
    const TYPE_PICTURE = 2;

    /**
     * 素材类型: 视频链接
     */
    const TYPE_VIDEO = 3;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        static::addGlobalScope('orderByIdDesc', function (Builder $builder) {
            $builder->orderByDesc($builder->getModel()->getTable() . '.' . $builder->getModel()->getKeyName());
        });
    }

    public function commodityActivity()
    {
        return $this->belongsTo(CommodityActivity::class);
    }
}
